<template>
  <div class="dashboard-container">
    <div class="bgc">
      <div
        class="title"
        style="
          width: 100%;
          color: #fff;
          font-weight: 500;
          font-size: 24px;

          box-sizing: border-box;
          padding-left: 20px;
          display: flex;
          align-items: center;
          margin-top: 20px;
          margin-bottom: 30px;
        "
      >
        添加/编辑设备
      </div>
      <el-steps :active="type" style="width: 500px; margin: 0 auto">
        <el-step title="基础配置"></el-step>
        <el-step title="高级配置"></el-step>
        <el-step title="预警配置"></el-step>
        <el-step title="完成"></el-step>
      </el-steps>
      <div v-if="type == 1" class="forms">
        <el-form :model="form" :rules="rules" ref="form" label-width="100px" class="demo-ruleForm">
          <el-form-item label="名称" prop="name">
            <el-input class="el-inputs" v-model="form.name"></el-input>
          </el-form-item>
          <el-form-item label="安装位置" prop="">
            <el-input class="el-inputs" v-model="form.location"></el-input>
          </el-form-item>
          <el-form-item label="组：" prop="">
            <el-input class="el-inputs" v-model="form.group"></el-input>
          </el-form-item>
          <el-form-item label="曲线类型：" prop="">
            <el-select v-model="form.line_type" placeholder="请选择活动区域">
              <el-option label="区域一" value="shanghai"></el-option>
              <el-option label="区域二" value="beijing"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="单位：" prop="">
            <el-input
              class="el-inputs"
              style="background-color: transparent"
              v-model="form.unit"
            ></el-input>
          </el-form-item>
          <!-- <el-form-item label="活动时间" required>
              <el-col :span="11">
                <el-form-item prop="date1">
                  <el-date-picker
                    type="date"
                    placeholder="选择日期"
                    v-model="form.date1"
                    style="width: 100%"
                  ></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col class="line" :span="2">-</el-col>
              <el-col :span="11">
                <el-form-item prop="date2">
                  <el-time-picker
                    placeholder="选择时间"
                    v-model="form.date2"
                    style="width: 100%"
                  ></el-time-picker>
                </el-form-item>
              </el-col>
            </el-form-item> -->
          <!-- <el-form-item label="即时配送" prop="delivery">
              <el-switch v-model="form.delivery"></el-switch>
            </el-form-item>
            <el-form-item label="活动性质" prop="type">
              <el-checkbox-group v-model="form.type">
                <el-checkbox label="美食/餐厅线上活动" name="type"></el-checkbox>
                <el-checkbox label="地推活动" name="type"></el-checkbox>
                <el-checkbox label="线下主题活动" name="type"></el-checkbox>
                <el-checkbox label="单纯品牌曝光" name="type"></el-checkbox>
              </el-checkbox-group>
            </el-form-item>
            <el-form-item label="特殊资源" prop="resource">
              <el-radio-group v-model="form.resource">
                <el-radio label="线上品牌商赞助"></el-radio>
                <el-radio label="线下场地免费"></el-radio>
              </el-radio-group>
            </el-form-item> -->
          <el-form-item label="备注" prop="">
            <el-input type="textarea" v-model="form.remark"></el-input>
          </el-form-item>
          <el-form-item class="" style="display: flex; justify-content: center">
            <el-button type="primary" style="margin: 0 auto" @click="submitForm('form')"
              >下一步</el-button
            >
          </el-form-item>
        </el-form>
      </div>
      <div v-if="type == 2" class="forms">
        <el-form :model="form" :rules="rules" ref="form" label-width="100px" class="demo-ruleForm">
          <el-form-item label="校准系统" prop="">
            <el-input class="el-inputs" v-model="form.calibration_factors"></el-input>
          </el-form-item>
          <el-form-item label="公式" prop="">
            <el-input class="el-inputs" v-model="form.formula"></el-input>
          </el-form-item>
          <el-form-item label="基准值" prop="">
            <el-input class="el-inputs" v-model="form.base_value"></el-input>
          </el-form-item>
          <!-- <el-form-item label="曲线类型：" prop="">
              <el-select v-model="form.line_type" placeholder="请选择活动区域">
                <el-option label="区域一" value="shanghai"></el-option>
                <el-option label="区域二" value="beijing"></el-option>
              </el-select>
            </el-form-item> -->
          <el-form-item label="基准值时间：" prop="">
            <el-input
              class="el-inputs"
              style="background-color: transparent"
              v-model="form.base_time"
            ></el-input>
          </el-form-item>
          <el-form-item label="小数位数：" prop="">
            <el-input
              class="el-inputs"
              style="background-color: transparent"
              v-model="form.decimals"
            ></el-input>
          </el-form-item>
          <el-form-item label="Ascli文件" prop="">
            <el-input
              class="el-inputs"
              style="background-color: transparent"
              v-model="form.ascii_file"
            ></el-input>
          </el-form-item>
          <el-form-item label="在文件第几列" prop="">
            <el-input
              class="el-inputs"
              style="background-color: transparent"
              v-model="form.in_file"
            ></el-input>
          </el-form-item>
          <el-form-item label="日期格式化" prop="">
            <el-input
              class="el-inputs"
              style="background-color: transparent"
              v-model="form.date_format"
            ></el-input>
          </el-form-item>
          <!-- <el-form-item label="活动时间" required>
              <el-col :span="11">
                <el-form-item prop="date1">
                  <el-date-picker
                    type="date"
                    placeholder="选择日期"
                    v-model="form.date1"
                    style="width: 100%"
                  ></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col class="line" :span="2">-</el-col>
              <el-col :span="11">
                <el-form-item prop="date2">
                  <el-time-picker
                    placeholder="选择时间"
                    v-model="form.date2"
                    style="width: 100%"
                  ></el-time-picker>
                </el-form-item>
              </el-col>
            </el-form-item> -->
          <!-- <el-form-item label="即时配送" prop="delivery">
              <el-switch v-model="form.delivery"></el-switch>
            </el-form-item>
            <el-form-item label="活动性质" prop="type">
              <el-checkbox-group v-model="form.type">
                <el-checkbox label="美食/餐厅线上活动" name="type"></el-checkbox>
                <el-checkbox label="地推活动" name="type"></el-checkbox>
                <el-checkbox label="线下主题活动" name="type"></el-checkbox>
                <el-checkbox label="单纯品牌曝光" name="type"></el-checkbox>
              </el-checkbox-group>
            </el-form-item>
            <el-form-item label="特殊资源" prop="resource">
              <el-radio-group v-model="form.resource">
                <el-radio label="线上品牌商赞助"></el-radio>
                <el-radio label="线下场地免费"></el-radio>
              </el-radio-group>
            </el-form-item> -->
          <!-- <el-form-item label="备注" prop="">
              <el-input type="textarea" v-model="form.remark"></el-input>
            </el-form-item> -->
          <el-form-item class="" style="display: flex; justify-content: center">
            <el-button
              type="primary"
              style="margin: 0 auto; background-color: transparent; margin-right: 20px"
              @click="out()"
              >上一步</el-button
            >
            <el-button type="primary" style="margin: 0 auto" @click="submitForm('form')"
              >下一步</el-button
            >
          </el-form-item>
        </el-form>
      </div>

      <div v-if="type == 3" class="forms">
        <el-form :model="form" :rules="rules" ref="form" label-width="100px" class="demo-ruleForm">
          <el-form-item label="看门狗阈值" prop="">
            <el-input class="el-inputs" v-model="form.watch_dog"></el-input>
          </el-form-item>
          <el-form-item label="橙色预警下限" prop="">
            <el-input class="el-inputs" v-model="form.orange_lower"></el-input>
          </el-form-item>
          <el-form-item label="橙色预警上限" prop="">
            <el-input class="el-inputs" v-model="form.orange_upper"></el-input>
          </el-form-item>
          <el-form-item label="红色预警下限" prop="">
            <el-input class="el-inputs" v-model="form.red_lower"></el-input>
          </el-form-item>
          <el-form-item label="红色预警上限" prop="">
            <el-input class="el-inputs" v-model="form.red_upper"></el-input>
          </el-form-item>
          <el-form-item label="黑色预警下限" prop="">
            <el-input class="el-inputs" v-model="form.black_lower"></el-input>
          </el-form-item>
          <el-form-item label="黑色预警上限" prop="">
            <el-input class="el-inputs" v-model="form.black_upper"></el-input>
          </el-form-item>

          <el-form-item class="" style="display: flex; justify-content: center">
            <el-button
              type="primary"
              style="margin: 0 auto; background-color: transparent; margin-right: 20px"
              @click="out()"
              >上一步</el-button
            >
            <el-button type="primary" style="margin: 0 auto" @click="submitForms('form')"
              >提交</el-button
            >
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>
  <script>
import { sensor_edit } from '@/api/user'
export default {
  computed: {},
  data() {
    return {
      info: {},
      type: 1,
      form: {
        id: '',
        name: '',
        location: '',
        group: '',
        line_type: '',
        unit: '',
        remark: '',
        calibration_factors: '',
        formula: '',
        base_value: '',
        base_time: '',
        decimals: '',
        ascii_file: '',
        in_file: '',
        date_format: '',
        watch_dog: '',
        orange_lower: '',
        orange_upper: '',
        red_lower: '',
        red_upper: '',
        black_lower: '',
        black_upper: ''
      },
      rules: {
        name: [{ required: true, message: '请输入活动名称', trigger: 'blur' }]
        // region: [{ required: true, message: '请选择活动区域', trigger: 'change' }],
        // date1: [{ type: 'date', required: true, message: '请选择日期', trigger: 'change' }],
        // date2: [{ type: 'date', required: true, message: '请选择时间', trigger: 'change' }],
        // type: [
        //   { type: 'array', required: true, message: '请至少选择一个活动性质', trigger: 'change' }
        // ],
        // resource: [{ required: true, message: '请选择活动资源', trigger: 'change' }],
        // desc: [{ required: true, message: '请填写活动形式', trigger: 'blur' }]
      }
    }
  },
  created() {
    // this.optionsValue = this.options[0]
    if (JSON.parse(this.$route.query.item)) {
      let tom = JSON.parse(this.$route.query.item)
      this.form = tom
    }
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.type = this.type + 1
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    submitForms(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          sensor_edit(this.form).then(res => {
            // console.log(res, '--111111')
            if (res.code === 200) {
              this.$message({
                message: '修改成功',
                type: 'success'
              })
              this.type = this.type + 1

              setTimeout(() => {
                this.$router.push({ path: 'equipmentManagement' })
              }, 2000)
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    out() {
      this.type = this.type - 1
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>
  
  <style lang="scss" scoped>
.bgc {
  width: 90%;
  margin: 0 auto;
  height: 80vh;
  border: 1px solid rgb(101, 166, 231);
  // background-color: red;
  //   width: 400px;
  //  height: 300px;
  //  background-color: #222 !important;
  //  border-radius: 10px;
  //  display: flex;
  //  align-items: center;
  //  justify-content: center;
  //  font-size: 20px;
  //  color: #fff;
  //  font-weight: 800;
  //  position: relative;
  //  z-index: 20;
  // background: url('../../views/images/编组-3-20240612172302722_副本.png');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  // background-color: red;
}
::v-deep .el-step__title.is-success {
  color: #fff;
}
::v-deep .el-step__title.is-process {
  color: #ccc !important;
}
.demo-ruleForm {
  width: 500px;
  margin: 0 auto;
  margin-top: 20px;
}
.forms {
  width: 800px;
  margin: 0 auto;
}
::v-deep .el-input__inner {
  background-color: transparent !important;
  color: #fff;
}
::v-deep .el-textarea__inner {
  background-color: transparent !important;
  color: #fff;
}
</style>